const fs = require("fs");
const path = require("../utils/path");
const traverse = require("@babel/traverse").default;
const babelParse = require("@babel/parser");
const generate = require("@babel/generator").default;
const babelCore = require("@babel/core");
const myPlugin = require("./plugin/babel-plugin-MyPlugin");

const code = fs.readFileSync(
  path.resolve("./config/babel/src/file.js"),
  "utf-8"
);

 babelCore.transformFileAsync(path.resolve("./config/babel/src/file.js"), {
  plugins: [
    [
      myPlugin,
      {
        whenFalsy: "liaocaimin",
      }
    ]
  ],
}).then(res => {
  console.log(res.code)
})


// const ast = babelParse.parse(code, {
//   sourceType: 'module'
// });

// traverse(ast, {
//   Identifier (path) {
//     path.node.name =  path.node.name.split('').reverse().join('')
//   }
// })

// const tCode = generate(ast).code;
// console.log(tCode);
